// dp_image_compression

/**
input:
16
10 9 12 40 50 35 15 12 8 10 9 15 11 130 160 240
answer: N/A

input:
6
10 12 15 255 1 2
answer: 57
10 12 15 | 255 | 1 2
*/

#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
using namespace std;

constexpr int max_len = 256; //8 bit, max length， len=0 means 1 item
constexpr int max_bit = 8; //3 bit, max value 2^8-1=255
constexpr int seg_meta = 11; //2 bits length + 3 bits value

int main() {
    int c;
    cin >> c;
    vector<int> min_mem(c), min_bit(c); // s[i]:min_mem of first i pixel, b[i]:min bit of pixel i
    vector<int> prev_seg(c); //from a segment's end, point to previous segment's end

    // i: i-th pixel
    for (int i = 0; i < c; i++) {
        int tmp;
        cin >> tmp;

        min_mem[i] = numeric_limits<int>::max();
        // +1: we need 2bit for 2 = 2^1 = 0b10
        min_bit[i] = static_cast<int>(ceil(log2(tmp + 1)));

        // find min_mem of first i pixels
        for (int seg_len = 1; seg_len <= max_len; seg_len++) {
            const int seg_start = i - seg_len + 1;
            if (seg_start < 0) break;

            // find max bit in segment
            int seg_bit = numeric_limits<int>::min();
            for (int j = seg_start; j <= i; j++)
                seg_bit = max(min_bit[j], seg_bit);

            int seg_mem = seg_len * seg_bit + seg_meta;
            int prev_mem = seg_start > 0 ? min_mem[seg_start - 1] : 0;
            int new_mem = prev_mem + seg_mem;

            min_mem[i] = min(new_mem, min_mem[i]);

            if (new_mem == min_mem[i]) {
                prev_seg[i] = seg_start - 1;
            }

            cout << "len=" << seg_len << ", bit=" << seg_bit << ", seg[" << seg_start << ", " << i << "], ";
            cout << "seg_mem=" << seg_mem << ", new_mem=" << new_mem << endl;
        }
        cout << "min_mem[" << i << "]=" << min_mem[i] << endl;

        vector<int> segments;
        for (int pos = prev_seg[i]; pos > 0; pos = prev_seg[pos])
            segments.emplace(segments.begin(), pos);
        cout << "[0,";
        for (const auto &end: segments)
            cout << end << "][" << end + 1 << ",";
        cout << i << "]" << endl;
    }

    return 0;
}
